let mongoose = require('./db');

const employeeSchema = new mongoose.Schema({
  name: String, //用户名
  password: String, //密码
  level: String, //用户等级
  //链接角色表
  role: {
    type: [mongoose.Schema.Types.ObjectId],
    ref: 'role',
  },

  department: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'department',
  },
});

//角色表
const roleSchema = new mongoose.Schema({
  name: String, //角色名称
  //连接部门表
});

//权限
const permissionSchema = new mongoose.Schema({
  name: String, //名字
  level: Number, //权限等级
  path: String, //权限url

  children: {
    type: [mongoose.Schema.Types.ObjectId],
    ref: 'permission',
  },
});

const employeeModel = mongoose.model('employee', employeeSchema, 'employee');
const roleModel = mongoose.model('role', roleSchema, 'role');
const permissionModel = mongoose.model(
  'permission',
  permissionSchema,
  'permission',
);
//部门
const departmentSchema = new mongoose.Schema({
  name: String, //部门名称
  shangjibumen: String,//上级部门
  status: Number,//状态
  biezhu: String,//备注
  //连接权限表
});

const video_typeSchema = new mongoose.Schema({
  type_name: String, //视频分类名称
  type_img: String, //视频分类图片
  type_desc: String, //视频分类描述
  type_video: {
    type: [mongoose.Schema.Types.ObjectId],
    ref: 'video',
  }, //视频分类下的视频
});
const video_typeModel = mongoose.model(
  'video_type',
  video_typeSchema,
  'video_type',
); //视频分类

//审核员
const video_employeeSchema = new mongoose.Schema({
  employee_name: String, //审核员名称
  employee_password: String, //审核员密码
  employee_time: Number, //审核员注册时间
});

// ---------------------前端-----------------
// 用户
const loginSchema = new mongoose.Schema({
  tel: String, //电话
  password: String, //密码
  name: String, //用户名
  image: String, //头像
  my_video: Array, //我的视频
  my_like: Array, //我的点赞
  my_shoucang: Array, //我的收藏
  my_guanzhu: Array, //我的关注
  my_fensi: Array, //我的粉丝
  my_desc: String, //个人简介
  whether_business: Boolean, //是否是商家
  authentication: Boolean, //是否实名认证
  vip_grade: String, //会员等级
  my_location: String, //所在地
  WC_nickname: String, //微信昵称

  wealth: Number, //财富值
  autograph: String, //个性签名
  headPortrait: String, //头像
  birthday: String, //生日
  my_wallet: {
    type: [mongoose.Schema.Types.ObjectId],
    ref: 'wallet',
  }, //钱包
  team_name: {
    type: [mongoose.Schema.Types.ObjectId],
    ref: 'team',
  }, //我的团队
  WX_statue: Boolean, //是否显示微信号
  tel_statue: Boolean, //是否显示电话
  personality_statue: String, //个性化推荐
});

// 视频
const videoSchema = new mongoose.Schema({
  user_id: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'login',
  }, //上传人
  src: String, //视频地址
  video_desc: String, //视频简介
  video_time: Date, //上传时间
  video_address: String, //上传地点
  video_state: Boolean, //视频状态
  video_thumbs_up: Number, //点赞
  video_collection: Number, //收藏
  video_comment: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'comment',
  }, //视频评论
});

// 点赞
const thumbs_upSchema = new mongoose.Schema({
  user_id: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'login',
  }, //点赞人
  video_id: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'video',
  }, //点赞的视频
  thumbs_up_state: Boolean, //是否点赞
});

// 收藏
const collectionShema = new mongoose.Schema({
  user_id: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'login',
  }, //收藏人
  video_id: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'video',
  }, //收藏的视频
  collection_state: Boolean, //是否收藏
});

// 评论
const commentSchema = new mongoose.Schema({
  user_id: {
    type: [mongoose.Schema.Types.ObjectId],
    ref: 'login',
  }, //评论人
  video_id: {
    type: [mongoose.Schema.Types.ObjectId],
    ref: 'video',
  }, //评论的视频
  comment_time: Date, //评论时间
  comment_content: String, //评论内容
  // 评论点赞数量
});

// 关注
const followSchema = new mongoose.Schema({
  user_id: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'login',
  }, //关注人
  followed_id: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'login',
  }, //被关注人
});
const followsModel = mongoose.model('follow', followSchema,'follows');
// const videoSchema = new mongoose.Schema({
//   user_id: {
//     type: mongoose.Schema.Types.ObjectId,
//     ref: 'login',
//   }, //上传人
//   src: String, //视频地址
//   video_desc: String, //视频简介
//   video_time: Date, //上传时间
//   video_address: String, //上传地点
//   video_state:Boolean, //视频状态
//   video_thumbs_up: {
//     type: mongoose.Schema.Types.ObjectId,
//   }, //视频点赞
//   video_collection: {
//     type: mongoose.Schema.Types.ObjectId,
//     ref: 'collection',
//   }, //视频收藏
//   video_comment: {
//     type: mongoose.Schema.Types.ObjectId,
//     ref: 'comment',
//   }, //视频评论
// });

const videobackSchema = new mongoose.Schema({
  title: String, //视频标题
  imgscr: String, //视频封面,
  type_video: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'video_type',
  },
  status: Number, //视频状态 0:未审核 1:已审核 2:审核不通过
  status_user: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'video_employee',
  },
  user_id: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'login',
  }, //上传人
  src: String, //视频地址
  video_desc: String, //视频简介
  video_time: Date, //上传时间
  video_address: String, //上传地点
  video_state: Boolean, //视频状态
  video_thumbs_up: {
    type: mongoose.Schema.Types.ObjectId,
  }, //视频点赞
  video_collection: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'collection',
  }, //视频收藏
  video_comment: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'comment',
  }, //视频评论
  shop_type: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'shop_type',
  },
  chuangzuojibie: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'chuangzuojibie',
  },
});

const videobackModel = mongoose.model(
  'videoback',
  videobackSchema,
  'videoback',
);

const departmentModel = mongoose.model(
  'department',
  departmentSchema,
  'department',
); //后台用户登录信息

//访问量
const visitnumSchema = new mongoose.Schema({
  visit_time: Number, //访问时间
  visit_id: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'login',
  },
});

const visitModel = mongoose.model('visitnum', visitnumSchema, 'visitnum');

//长短视频类型表
const shop_typeSchema = new mongoose.Schema({
  name: String, //长视频 短视频等
});
const shop_typeModel = mongoose.model(
  'shop_type',
  shop_typeSchema,
  'shop_type',
);

//商品表
const goodsSchema = new mongoose.Schema({
  name: String, //商品名称
  price: Number, //商品价格
  img: String, //商品图片
  type_id: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'shop_type',
  }, //商品类型
  sale_num: Number, //销量
  goods_num: Number, //库存
  goods_desc: String, //商品描述
  goods_time: Date, //商品上架时间
  //////************ */
  is_out: String, //退款情况
  reservation: String, //预约情况
  refund: String, //退款情况
  statking: String, //是否可叠加
  purchase: Array, //套餐内容
  end_time: String, //有效时间
  ok_time: String, //使用时间
  no_time: String, //不可用时间
  range: String, //适用范围
  detailts: Number, //折扣
  store: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'shops',
  }, //店铺
  goodsStyle: String, //商品类型
  imgs: Array, //商品图片
  num: Number, //商品数量
});

//店铺表
const shopsSchema = new mongoose.Schema({
  shopname: String, //店铺名称
  shop_img: String, //店铺图片
  stresst: String, //店铺街道地址
  type: String, //店铺类型
  time: String, //营业时间
  address: String, //店铺具体地址
  tel: String, //店铺电话
  goodsAll: {
    type: Array,
    ref: 'goods',
  }, //商品
  statue: String, //店铺营业状态
  text: String, //店铺简介
  distance: Number, //距离
});
const shopsModel = mongoose.model('shops', shopsSchema, 'shops');

const goodsModel = mongoose.model('goods', goodsSchema, 'goods');
//支付  销售公用一个表
const payMoneySechma = new mongoose.Schema({
  pay_time: Number, //支付时间
  pay_money: Number, //支付金额
  goods_id: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'goods',
  }, //商品id

  pay_id: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'login',
  },
});

const video_employeeModel = mongoose.model(
  'video_employee',
  video_employeeSchema,
  'video_employee',
);
const payMoneyModel = mongoose.model('payMoney', payMoneySechma, 'payMoney');
//------------------ 前端----------------------
const loginModel = mongoose.model('login', loginSchema, 'login'); //前端用户登录信息
const videoModel = mongoose.model('video', videoSchema, 'video'); //前端视频信息
const thumbs_upModel = mongoose.model(
  'thumbs_up',
  thumbs_upSchema,
  'thumbs_up',
); //前端点赞信息
const commentModel = mongoose.model('comment', commentSchema, 'comment'); //视频评论信息
const collectionModel = mongoose.model(
  'collection',
  collectionShema,
  'collection',
); //视频收藏信息

//创作级别管理
const chuangzuojibieSchema = new mongoose.Schema({
  level: Number, //创作级别
  level_name: String, //创作级别名称
  level_desc: String, //创作级别描述
  level_time: Number, //创作级别时间
  level_state: Number, //创作级别状态
});

const chuangzuojibieModel = mongoose.model(
  'chuangzuojibie',
  chuangzuojibieSchema,
  'chuangzuojibie',
);

const AppwailianSchema = new mongoose.Schema({
  title: String, //标题
  url: String, //链接地址
  start_time: Number, //开始时间
  status: Number, //状态
  appcode: String, //appcode
  appID: String, //appID
});

//体现管理
const tixianSchema = new mongoose.Schema({
  tixian_time: Number, //提现时间
  tixian_money: Number, //提现金额
  tixian_state: Number, //提现状态
  tixian_employee: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'video_employee',
  },
  tixian_id: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'login',
  },
  tixian_ID: String,
});

const tixianModel = mongoose.model('tixian', tixianSchema, 'tixian');

//会员管理
const huiyuandingdan = new mongoose.Schema({
  huiyuan_time: Number, //会员时间
  huiyuan_money: Number, //会员金额
  huiyuan_state: Number, //会员状态
  huiyuan_ID: String,
  huiyuna_buy_con: String, //会员购买内容
  huiyuan_buy_money: Number, //会员购买金额
  huiyuan_id: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'login',
  },
});

const huiyuandingdanModel = mongoose.model(
  'huiyuandingdan',
  huiyuandingdan,
  'huiyuandingdan',
);

const AppwailianModel = mongoose.model(
  'Appwailian',
  AppwailianSchema,
  'Appwailian',
);

const XiaoshouoeSchema = new mongoose.Schema({
  xiaoshoue_time: String, //销售额时间
  xiaoshoue_money: Number, //销售额金额
});

const PutongyonghuSchema = new mongoose.Schema({
  putongyonghu_state: Number,
  putongyonghu_name: String,
  putongyonghu_tell: Number,
  putongyonghu_sex: Number,
  putongyonghu_yue: Number,
  putongyonghu_zhuborenzheng: Number,
  putongyonghu_zhucetime: Number,
});

const PutongyonghuModel = mongoose.model(
  'Putongyonghu',
  PutongyonghuSchema,
  'Putongyonghu',
);

const xiaoshoueModel = mongoose.model(
  'xiaoshoue',
  XiaoshouoeSchema,
  'xiaoshoue',
);

const chuanbzuozheguanliSchema = new mongoose.Schema({
  chuanbzuozhe_name: String, //发布者名称
  chuanbzuozhe_zhuce_time: Number, //发布时间
  chuanbzuozhe_state: Number, //发布状态
  chuanbzuozhe_tell: Number, //发布者电话
  chuanbzuozhe_sex: Number,
  chuangzuozhe_longthvideonum: Number,
  hcuangzuozhe_shortvideonum: Number,
  chuanbzuozhe_dengji: Number,
});

const chuanbzuozheguanliModel = mongoose.model(
  'chuanbzuozheguanli',
  chuanbzuozheguanliSchema,
  'chuanbzuozheguanli',
);

const PindaoSchema = new mongoose.Schema({
  pindao_name: String, //频道名称
  pindao_state: Number, //频道状态
  pindao_time: Number, //频道时间
  pindao_suoshuyemian: String, //所属页面
  pindao_paixuzhi: Number, //排序值
});

const PindaoModel = mongoose.model('Pindao', PindaoSchema, 'Pindao');

const GuanggaoSchema = new mongoose.Schema({
  guanggao_name: String, //广告名称
  guanggao_state: Number, //广告状态
  guanggao_start_time: Number, //广告时间
  guanggao_end_time: Number, //所属页面
  guanggao_yemian: String, //所属页面
  guanggao_paixuzhi: Number, //排序值
  guanggao_url: String,
});
const GuanggaoModel = mongoose.model('Guanggao', GuanggaoSchema, 'Guanggao');

const GiftSchema = new mongoose.Schema({
  gift_name: String, //礼物名称
  gift_price: Number, //礼物价格
  gift_state: Number, //礼物状态
  gift_create_time: Number, //礼物时间
  gift_url: String,
})

const GiftModel = mongoose.model('Gift', GiftSchema, 'Gift');

const changshipinfenleiSchema = new mongoose.Schema({
  changshipinfenlei_state: Number,
  changshipinfenlei_create_time: Number,
  changshipinfenlei_fenleiming: Number,
  changshipinfenlei_shangjifenlie: Number,
  changshipinfenlei_beizhu: String,
});
const ChangshipinfenleiModel = mongoose.model('Changshipinfenlei', changshipinfenleiSchema, 'Changshipinfenlei');

const jubaozhongxinSchema = new mongoose.Schema({
  jubaozhngxin_name: String,
  jubaozhngxin_phone: String,
  jubaozhngxin_content: String,
  jubaozhngxin_time: Number,
  jubaozhngxin_state: Number,
  jubaozhngxin_type: Number,
  jubaozhongxin_src: String,
  jubaozhongxin_duijiekefu: String,
  jubaozhongxin_gongdanleixing:String
})




const jubaozhongxinModel = mongoose.model('jubaozhongxin', jubaozhongxinSchema, 'jubaozhongxin');


const TongzhigonggaoSearch = new mongoose.Schema({
  tongzhigonggao_title: String,
  tongzhigonggao_suoshuyemian: String,
  tongzhigonggao_time: Number,
  tongzhigonggao_state: Number,
});


const tongzhigonggaoModel = mongoose.model('tongzhigonggao', TongzhigonggaoSearch, 'tongzhigonggao');

const  jeuseSchema = new mongoose.Schema({
  name: String,
  url: String,
  tell:Number
})

const rexiaocihengSchema = new mongoose.Schema({
  rexiaocheng_name: String,
  rexiaocheng_num: Number,
  rexiaocheng_zhouzhangfu: Number
})

const rexiaocihengModel = mongoose.model('rexiaociheng', rexiaocihengSchema, 'rexiaociheng');
const jeuseModel = mongoose.model('jeuse', jeuseSchema, 'jeuse');

module.exports = {
  employeeModel,
  roleModel,
  permissionModel,
  departmentModel,
  // ------------前端--------------
  loginModel,
  videoModel,
  thumbs_upModel,
  commentModel,
  collectionModel,
  shop_typeModel,
  payMoneyModel,
  visitModel,
  goodsModel,
  video_typeModel,
  video_employeeModel,
  shopsModel,
  followsModel,

  // videobackModel,
  videobackModel,
  chuangzuojibieModel,
  AppwailianModel,
  tixianModel,
  huiyuandingdanModel,
  xiaoshoueModel,
  PutongyonghuModel,
  chuanbzuozheguanliModel,
  PindaoModel,
  GuanggaoModel,
  GiftModel,
  ChangshipinfenleiModel,
  jubaozhongxinModel,
  tongzhigonggaoModel,
  jeuseModel,
  rexiaocihengModel,
};
